package com.cxhc.app.api;

import java.util.List;
import java.util.Map;
import com.cxhc.app.api.mapper.SysEnterpriseMapStructMapper;
import com.cxhc.app.api.vo.SysEnterpriseVo;
import com.cxhc.system.domain.app.SysEnterprise;
import com.cxhc.system.service.cockpit.ISysEntService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;

import javax.annotation.Resource;

/**
 * 企业Controller
 * 
 * @author Dhq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/api/sysEnterprise")
public class ApiSysEnterpriseApp extends BaseController
{
    @Resource
    private ISysEntService sysEnterpriseService;

    /**
     * 查询企业列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SysEnterpriseVo sysEnterpriseVo)
    {
        PageHelper.startPage(sysEnterpriseVo.getPageNum(),sysEnterpriseVo.getPageSize());
        SysEnterprise sysEnterprise = SysEnterpriseMapStructMapper.INSTANCE.SysEnterpriseVoToSysEnterprise(sysEnterpriseVo);
        Map<String, List<SysEnterprise>> stringListMap = sysEnterpriseService.selectSysEnterpriseList(sysEnterprise);
        return success(stringListMap);
    }

    /**
     * 获取企业详细信息
     */
    @GetMapping(value = "/details/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(sysEnterpriseService.selectSysEnterpriseByID(ID));
    }

    /**
     * 新增企业
     */
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody SysEnterpriseVo sysEnterpriseVo)
    {
        SysEnterprise sysEnterprise = SysEnterpriseMapStructMapper.INSTANCE.SysEnterpriseVoToSysEnterprise(sysEnterpriseVo);

        return toAjax(sysEnterpriseService.insertSysEnterprise(sysEnterprise));
    }

    /**
     * 修改企业
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SysEnterpriseVo sysEnterpriseVo)
    {
        SysEnterprise sysEnterprise = SysEnterpriseMapStructMapper.INSTANCE.SysEnterpriseVoToSysEnterprise(sysEnterpriseVo);

        return toAjax(sysEnterpriseService.updateSysEnterprise(sysEnterprise));
    }

    /**
     * 删除企业
     */
	@GetMapping("/delete")
    public AjaxResult remove(Long ID,Long areaID)
    {
        return toAjax(sysEnterpriseService.deleteSysEnterpriseByID(ID,areaID));
    }
}
